//接收get请求

const koa = require('koa');
const app = new koa();

//中间件 处理业务
app.use(async (ctx) => {
    //ctx : 上下文 包含request response
    //从request中获取query&querystring
    let request = ctx.request;
    let req_query = request.query;//query是请求地址?后面处理过的参数对象
    let req_querystring = request.querystring;//querystring是请求地址?后面的字符串
    
    //从ctx中直接获取query&querystring
    let ctx_query = ctx.query;
    let ctx_querystring = ctx.querystring;

    ctx.body = {
        url : ctx.url,
        req_query,
        req_querystring,
        ctx_query,
        ctx_querystring
    }
});

//监听
app.listen(3000, () => {
    console.log('Server is running at port 3000.');
});